package response

import (
	"net/http"
	"strings"
	"project-info/src/lib"
)

const (
	OK   = 0
	FAIL = 1
)

type Res struct {
	Code     int         `json:"code"`
	Msg      string      `json:"msg"`
	Data     interface{} `json:"data"`
	Redirect string      `json:"redirect"`
}

func JsonOk(c *lib.GinContext, data interface{}, msgs ...string) error {
	return c.JSON(http.StatusOK, Res{
		Code: OK,
		Msg:  strings.Join(msgs, ""),
		Data: data,
	})
}

func JsonFail(c *lib.GinContext, msg string) error {
	return c.JSON(http.StatusOK, Res{
		Code: FAIL,
		Msg:  msg,
	})
}

func JsonResponse(c *lib.GinContext, code int, data interface{}, msg string, redirect string) error {
	return c.JSON(http.StatusOK, Res{
		Code:     code,
		Msg:      msg,
		Data:     data,
		Redirect: redirect,
	})
}
